package net.lahuobao.util;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by fyu1 on 15/4/6.
 */
public class AliAddress {

    public String getRemoteAddr(HttpServletRequest request) {
        String address = request.getHeader("x-forwarded-for");
        if (address == null || address.length() == 0 || "unknown".equalsIgnoreCase(address)) {
            address = request.getHeader("Proxy-Client-IP");
        }
        if (address == null || address.length() == 0 || "unknown".equalsIgnoreCase(address)) {
            address = request.getHeader("WL-Proxy-Client-IP");
        }
        if (address == null || address.length() == 0 || "unknown".equalsIgnoreCase(address)) {
            address = request.getHeader("HTTP_CLIENT_IP");
        }
        if (address == null || address.length() == 0 || "unknown".equalsIgnoreCase(address)) {
            address = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (address == null || address.length() == 0 || "unknown".equalsIgnoreCase(address)) {
            address = request.getRemoteAddr();
        }
        return address;
    }
}
